﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="listOp.aspx.cs" Inherits="jnlamp.Web.mobile.listOp" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>杀虫灯系统平台</title>
    <link rel="stylesheet" type="text/css" href="easyui/themes/metro/easyui.css" />
    <link rel="stylesheet" type="text/css" href="easyui/themes/mobile.css" />
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css" />
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.mobile.js"></script>
    <script src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="../Script/datetime.js"></script>
    <script src="js/mobile.js"></script>
    <script type="text/javascript">
        var gprs_id = "";
        $(function () {
            initMenu();
            gprs_id = getUrlParam("gprs_id");
            InitGird();
            page_load();
        });
        //初始化表格
        function InitGird() {
            $('#tt').datagrid({
                url: '../api/hanlder.ashx', //请求数据的页面
                sortName: 'scd_set_opt_id', //排序字段
                idField: 'scd_set_opt_id', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                //height: '50%', //高度
                nowrap: true, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: false,
                singleSelect: true,
                method: 'post',
                columns: [[
                    {
                        title: '操作', field: 'scd_set_opt_id', width: 80, formatter: function (value, row, index) {

                            if (row.readcount == 0) {
                                return "-";
                            }
                            else {
                                return "&nbsp;<a style='color:red' href='javascript:' onclick='delScd(" + row.scd_set_opt_id + ");return false;'>删除</a>";
                            }



                        }
                    },
                    {
                        title: '操作对象', field: 'lamp_id', width: 100, sortable: true, formatter: function (value, row, index) {
                            if (value == "") {
                                return "网关";
                            }
                            else {
                                return value;
                            }
                        }
                    },
                    {
                        title: '指令', field: 'opt', width: 100, formatter: function (value, row, index) {
                            if (value == "OPEN01") {
                                return "全体开灯";
                            }
                            else if (value == "OPEN02") {
                                return "全体关闭";
                            }
                            else if (value == "OPEN03") {
                                return "奇数开灯";
                            }
                            else if (value == "OPEN04") {
                                return "偶数开灯";
                            }
                            else if (value == "OPEN05") {
                                return "三分之一开灯";
                            }
                            else if (value == "OPEN06") {
                                return "四分之一开灯";
                            }
                            else if (value == "OPEN09") {
                                return "长期关闭";
                            }
                            else if (value.indexOf("AOPEN") == 0) {
                                return "开" + value.substring(5, 8) + "号灯";
                            }
                            else if (value.indexOf("ACLOSE") == 0) {
                                return "关" + value.substring(6, 9) + "号灯";
                            }
                            else if (value == "RESET") {
                                return "恢复出厂设置";
                            }
                            else {
                                return value;
                            }
                        }
                    },
                    {
                        title: '读取次数', field: 'readcount', width: 80, formatter: function (value, row, index) {

                            if (row.readcount == 0) {
                                return "3";
                            }
                            else if (row.readcount == 1) {
                                return "2";
                            }
                            else if (row.readcount == 3) {
                                return "0";
                            }
                            else if (row.readcount == 2) {
                                return "1";
                            }
                            else {
                                return row.readcount + "";
                            }



                        }
                    },
                    { title: '读取时间', field: 'readtime', width: 150 },
                    { title: '设置成功次数', field: 'setcount', width: 150 }
                    
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "QueryOpt", "gprs_id": gprs_id },
                pageList: [10, 15, 20, 50, 100],
                pagePosition: 'bottom',
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true //行号

            });


        }
        //删除
        function delScd(scd_set_opt_id) {
            $.messager.confirm('提示', '你确定要删除这条信息吗？', function (r) {
                if (r) {
                    $.ajax({
                        type: "post",
                        dataType: "text",
                        url: '../api/hanlder.ashx?action=delScd&scd_set_opt_id=' + scd_set_opt_id,
                        success: function (data) {
                            if (null != data && "[]" != data) {
                                if (data[0] == "T") {
                                    //$.messager.alert("提示", "恭喜您，信息删除成功！", "info");
                                    reloadgrid();
                                }
                                else {
                                    //$.messager.alert("提示", "信息删除失败！", "info");
                                }

                            }
                        }
                    });
                }

            });

        }
        function reloadgrid() {
            $('#tt').datagrid('reload');
        }
        function page_load() {
            if (gprs_id != "" && gprs_id != null) {
                $.ajax({
                    type: "post",
                    dataType: "json",
                    url: "../api/hanlder.ashx?action=QueryStatus&gprs_id=" + gprs_id,
                    success: function aa(data) {
                        if (null != data && "[]" != data) {
                            var kdsj = data[0].kdsj;
                            var kdsc = data[0].kdsc;
                            var ts = data[0].ts;
                            var opt = data[0].opt;

                            if (opt == "OPEN01") {
                                opt = "全体开灯";
                            }
                            else if (opt == "OPEN02") {
                                opt = "全体关闭";
                            }
                            else if (opt == "OPEN03") {
                                opt = "奇数开灯";
                            }
                            else if (opt == "OPEN04") {
                                opt = "偶数开灯";
                            }
                            else if (opt == "OPEN05") {
                                opt = "三分之一开灯";
                            }
                            else if (opt == "OPEN06") {
                                opt = "四分之一开灯";
                            }
                            else if (opt == "OPEN09") {
                                opt = "长期关闭";
                            }
                            else if (opt.indexOf("AOPEN") == 0) {
                                opt = "开" + opt.substring(5, 8) + "号灯";
                            }
                            else if (opt.indexOf("ACLOSE") == 0) {
                                opt = "关" + opt.substring(6, 9) + "号灯";
                            }
                            else if (opt == "RESET") {
                                opt = "恢复出厂设置";
                            }


                            if (ts == "0") {
                                ts = "长期运行"
                            }
                            else {
                                ts = "运行天数：" + ts;
                            }

                            kdsj = kdsj.substring(0, 2) + ":" + kdsj.substring(2, 4);
                            kdjc = kdsc.substring(0, 2) + "小时" + kdsc.substring(2, 4) + "分";

                            var content =  opt + "," + ts + ",开灯时间：" + kdsj + ",开灯时长：" + kdjc + "";

                            $("#lbl_status").html(content);
                        }

                    }
                });

            }

        }
    </script>
</head>
<body>

    <div class="easyui-navpanel" fit="true">
        <header>
            <div class="m-toolbar">
                <div  id="lbl_status"></div>
            </div>

        </header>      
        <div style="height: 100%;">
            <table id="tt" data-options="header:'#hh',singleSelect:true,border:false,fit:true,fitColumns:true,scrollbarSize:0">
            </table>
        </div>
        <footer>
            <div class="m-buttongroup m-buttongroup-justified" style="width: 100%">
                <a id="mymain" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-large-chart',size:'large',iconAlign:'top',plain:true">查看设备</a>
                <a id="equqtop" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-large-clipart',size:'large',iconAlign:'top',plain:true">群体操作</a>
                <a href="/mobile/equsdsz.aspx" class="easyui-linkbutton" data-options="iconCls:'icon-large-shapes',size:'large',iconAlign:'top',plain:true">单灯/时段设置</a>
                <a id="myexist" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-large-smartart',size:'large',iconAlign:'top',plain:true">退出</a>
            </div>
        </footer>
    </div>


</body>
</html>
